<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>对象方法</title>
</head>

<body>
  <script>
    let point = {
      x: 300,
      y: 400,
      toString() { return `${this.x},${this.y}` },
      toLocaleString: function () { return `${this.x.toLocaleString()},${this.y.toLocaleString()}` },
      valueOf: function () { return Math.hypot(this.x, this.y) },
      toJSON: function () { return this.toString() }
    }
    // toString()方法
    console.log(point.toString());
    // toLocaleString()方法
    console.log(point.toLocaleString());
    // valueOf()方法
    console.log(point.valueOf());
    console.log(point > 1);
    // toJSON()方法
    console.log(JSON.stringify([point]));

  </script>
</body>

</html>